package ciyuan.ChangeMinecraft;

import net.minecraft.entity.Entity;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.UUID;
import java.util.Vector;


/**
 * @author 150149
 */
@Mod.EventBusSubscriber
public class NoSpawnVillage {

    private static final Vector<UUID> deathEntity = new Vector<>();

    private synchronized static void die(Entity entity) {
        if (!deathEntity.contains(entity.getUUID())) {
            if (entity.isAlive()) {
                entity.kill();
            }
            deathEntity.add(entity.getUUID());
        }
    }

    @SubscribeEvent
    public static void onEntity(LivingSpawnEvent event) {
        if (event.getEntity().getEntity().getType().toString().toLowerCase().contains("village")) {
            die(event.getEntity());
        }
    }

}
